package com.ruoyi.web.controller.cashier;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.SySelfServiceBookingOrder;
import com.ruoyi.system.domain.SySelfServiceBookingOrderLog;
import com.ruoyi.system.dto.SelfServiceOrderQueryDTO;
import com.ruoyi.system.service.ISelfServiceBookingOrderService;
import com.ruoyi.system.util.BaseResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/booking/order")
@Api(tags = "自助预定订单管理")
public class SySelfServiceBookingOrderController extends BaseController {

    @Autowired
    private ISelfServiceBookingOrderService bookingOrderService;

    @ApiOperation("获取订单列表")
    @PostMapping("/list")
    public BaseResponse<IPage<SySelfServiceBookingOrder>> list(@RequestBody SelfServiceOrderQueryDTO queryDTO) {

        IPage<SySelfServiceBookingOrder> list = bookingOrderService.list(queryDTO);
        return BaseResponse.success(list);
    }
    @ApiOperation("获取订单详情")
    @GetMapping("/detail")
    public BaseResponse<SySelfServiceBookingOrder> detail(Long id) {
        if (id == null) {
            return BaseResponse.error("参数不能为空");
        }
        LambdaQueryWrapper<SySelfServiceBookingOrder> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(SySelfServiceBookingOrder::getId, id);
        SySelfServiceBookingOrder one = bookingOrderService.getOne(wrapper);
        return BaseResponse.success(one);
    }
    @ApiOperation("新增订单")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SySelfServiceBookingOrder order) {
        boolean result = bookingOrderService.save(order);
        return result ? AjaxResult.success(true) : AjaxResult.error("保存失败");
    }

}
